package de.stefanocke.roo.wicket.form.enumselect

import de.stefanocke.roo.wicket.Stereotypes
import de.stefanocke.roo.wicket.base.WicketItdBuilder
import java.lang.reflect.Modifier

import static de.stefanocke.roo.xtend.Method.*
import static de.stefanocke.roo.xtend.MethodSignature.*
import static de.stefanocke.roo.xtend.Parameter.*
import static extension de.stefanocke.roo.xtend.RooExtensions.*
import de.stefanocke.roo.wicket.base.PropertyFileChanges
import java.util.HashMap

class EnumSelectItdBuilder extends WicketItdBuilder implements PropertyFileChanges{
	override EnumSelectMetadata getMetadata(){
		super.metadata as EnumSelectMetadata
	} 

	override String baseClassStereotype(){
		Stereotypes::ENUM_SELECT
	}
	
	override getMethods(){
		var methods = constructors
		methods += enumValuesMethod
		methods
	}
	
	def getConstructors(){
		newArrayList(
			constructorWithIdAndMarkupProvider,
			constructorWithIdModelAndMarkupProvider
		)
	}
	
	def getEnumValuesMethod(){
		method(
			signature(Modifier::PUBLIC, modelClass.array(), "getEnumValues"),
			//TODO: Use persistence metadata here to determine method name
			[|'''
			return «modelClass.resolveStatic».values();
			''']
		)
	}
	
	override getPropertiesToAdd() {
		val result = new HashMap<String, String>()
		modelClassTypeDetails.classOrInterfaceTypeDetails.enumConstants.forEach(s | 
			result.put(modelClass.simpleTypeName+"."+s.symbolName, s.symbolName)
		)
		result
	}
	
	override getPropertiesToRename() {
		null
	}

}